package com.cw.lang.mybatis.dto;

import java.io.Serializable;

import lombok.Data;

/**
 * Description: PageParam.java
 *
 * @author chenw
 * @version 1.0
 * @date 2017年12月28日
 * @since v1.0
 */
@Data
public class PageParam implements Serializable {

    /** serialVersionUID */
    private static final long serialVersionUID = 4901705218363381498L;

    /**
     * pageNum
     */
    private Long pageNum = 1L;
    /**
     * pageSize 每页行数
     */
    private Long pageSize = 10L;

    public static final class Builder {

        private PageParam instance = new PageParam();

        private Builder() {}

        public static Builder getInstance() {
            return new Builder();
        }

        public Builder addPageNum(Long pageNum) {
            this.instance.setPageNum(pageNum);
            return this;
        }

        public Builder addPageSize(Long pageSize) {
            this.instance.setPageSize(pageSize);
            return this;
        }

        public PageParam build() {
            return this.instance;
        }
    }

    /**
     * 获取分页开始位置
     *
     * @return Long 分页开始位置
     */
    public Long getOffsetStart() {
        Long start = (pageNum - 1) * pageSize;
        return start >= 0 ? start : 0;
    }

}
